package com.ibm.risk.irmp.workflow.client.flowable.api;

import com.ibm.risk.irmp.workflow.client.flowable.ApiClient;

import com.ibm.risk.irmp.workflow.client.flowable.model.RestIdentityLink;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;


@Component("com.ibm.risk.irmp.flowable.api.TaskIdentityLinksApi")
public class TaskIdentityLinksApi {
    private ApiClient apiClient;

    public TaskIdentityLinksApi() {
        this(new ApiClient());
    }

    @Autowired
    public TaskIdentityLinksApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /**
     * Create an identity link on a task
     * It is possible to add either a user or a group.
     * <p><b>200</b> - successful operation
     * <p><b>201</b> - Indicates the task was found and the identity link was created.
     * <p><b>404</b> - Indicates the requested task was not found or the task does not have the requested identityLink. The status contains additional information about this error.
     * @param taskId The taskId parameter
     * @param body The body parameter
     * @return RestIdentityLink
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public RestIdentityLink createTaskInstanceIdentityLinks(String taskId, RestIdentityLink body) throws RestClientException {
        Object postBody = body;

        // verify the required parameter 'taskId' is set
        if (taskId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'taskId' when calling createTaskInstanceIdentityLinks");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("taskId", taskId);
        String path = UriComponentsBuilder.fromPath("/runtime/tasks/{taskId}/identitylinks").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<RestIdentityLink> returnType = new ParameterizedTypeReference<RestIdentityLink>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Delete an identity link on a task
     *
     * <p><b>204</b> - Indicates the task and identity link were found and the link has been deleted. Response-body is intentionally empty.
     * <p><b>404</b> - Indicates the requested task was not found or the task does not have the requested identityLink. The status contains additional information about this error.
     * @param taskId The taskId parameter
     * @param family The family parameter
     * @param identityId The identityId parameter
     * @param type The type parameter
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public void deleteTaskInstanceIdentityLinks(String taskId, String family, String identityId, String type) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'taskId' is set
        if (taskId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'taskId' when calling deleteTaskInstanceIdentityLinks");
        }

        // verify the required parameter 'family' is set
        if (family == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'family' when calling deleteTaskInstanceIdentityLinks");
        }

        // verify the required parameter 'identityId' is set
        if (identityId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'identityId' when calling deleteTaskInstanceIdentityLinks");
        }

        // verify the required parameter 'type' is set
        if (type == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'type' when calling deleteTaskInstanceIdentityLinks");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("taskId", taskId);
        uriVariables.put("family", family);
        uriVariables.put("identityId", identityId);
        uriVariables.put("type", type);
        String path = UriComponentsBuilder.fromPath("/runtime/tasks/{taskId}/identitylinks/{family}/{identityId}/{type}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = { };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};
        apiClient.invokeAPI(path, HttpMethod.DELETE, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Get a single identity link on a task
     *
     * <p><b>200</b> - Indicates the task and identity link was found and returned.
     * <p><b>404</b> - Indicates the requested task was not found or the task does not have the requested identityLink. The status contains additional information about this error.
     * @param taskId The taskId parameter
     * @param family The family parameter
     * @param identityId The identityId parameter
     * @param type The type parameter
     * @return RestIdentityLink
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public RestIdentityLink getTaskInstanceIdentityLinks(String taskId, String family, String identityId, String type) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'taskId' is set
        if (taskId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'taskId' when calling getTaskInstanceIdentityLinks");
        }

        // verify the required parameter 'family' is set
        if (family == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'family' when calling getTaskInstanceIdentityLinks");
        }

        // verify the required parameter 'identityId' is set
        if (identityId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'identityId' when calling getTaskInstanceIdentityLinks");
        }

        // verify the required parameter 'type' is set
        if (type == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'type' when calling getTaskInstanceIdentityLinks");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("taskId", taskId);
        uriVariables.put("family", family);
        uriVariables.put("identityId", identityId);
        uriVariables.put("type", type);
        String path = UriComponentsBuilder.fromPath("/runtime/tasks/{taskId}/identitylinks/{family}/{identityId}/{type}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<RestIdentityLink> returnType = new ParameterizedTypeReference<RestIdentityLink>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * List identity links for a task for either groups or users
     * Returns only identity links targeting either users or groups. Response body and status-codes are exactly the same as when getting the full list of identity links for a task.
     * <p><b>200</b> - Indicates the task was found and the requested identity links are returned.
     * <p><b>404</b> - Indicates the requested task was not found.
     * @param taskId The taskId parameter
     * @param family The family parameter
     * @return List&lt;RestIdentityLink&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public List<RestIdentityLink> listIdentityLinksForFamily(String taskId, String family) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'taskId' is set
        if (taskId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'taskId' when calling listIdentityLinksForFamily");
        }

        // verify the required parameter 'family' is set
        if (family == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'family' when calling listIdentityLinksForFamily");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("taskId", taskId);
        uriVariables.put("family", family);
        String path = UriComponentsBuilder.fromPath("/runtime/tasks/{taskId}/identitylinks/{family}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<List<RestIdentityLink>> returnType = new ParameterizedTypeReference<List<RestIdentityLink>>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * List identity links for a task
     *
     * <p><b>200</b> - Indicates the task was found and the requested identity links are returned.
     * <p><b>404</b> - Indicates the requested task was not found.
     * @param taskId The taskId parameter
     * @return List&lt;RestIdentityLink&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public List<RestIdentityLink> listTasksInstanceIdentityLinks(String taskId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'taskId' is set
        if (taskId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'taskId' when calling listTasksInstanceIdentityLinks");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("taskId", taskId);
        String path = UriComponentsBuilder.fromPath("/runtime/tasks/{taskId}/identitylinks").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<List<RestIdentityLink>> returnType = new ParameterizedTypeReference<List<RestIdentityLink>>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
}
